<?php
/**
 * PnmPictures.php
 *
 * PHP version 5
 *
 * LICENSE: This source file is subject to version 2.0 of the Apache license
 * that is available through the world-wide-web at the following URI:
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * @category Controller
 * @package  Controller
 * @author   Alex Kopp <koppa@rpi.edu>
 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @link     http://http://code.google.com/p/tri-chi/
 */

/**
 * PnmPictures
 *
 * The model that manages PNM Pictures
 * 
 * The followings are the available columns in table 'pnm_pictures':
 * 
 * @property string $id
 * @property string $filename
 * @property string $thumbnail_filename
 *
 * The followings are the available model relations:
 * @property Pnm[] $pnms
 *
 * @category Controller
 * @package  Controller
 * @author   Alex Kopp <koppa@rpi.edu>
 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @link     http://http://code.google.com/p/tri-chi/
 */
class PnmPictures extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * 
     * @param unknown_type $className Class name
     * 
     * @return PnmPictures the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * Table Name
     * 
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'pnm_pictures';
    }

    /**
     * Validation Rules
     * 
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('filename, thumbnail_filename', 'required'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, filename, thumbnail_filename', 'safe', 'on'=>'search'),
        );
    }

    /**
     * Table Relations
     * 
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'pnms' => array(self::HAS_MANY, 'Pnm', 'picture_id'),
        );
    }

    /**
     * Attribute Labels
     * 
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'filename' => 'Filename',
            'thumbnail_filename' => 'Thumbnail Filename',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * 
     * @return CActiveDataProvider data provider that returns models based on search
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id', $this->id, true);
        $criteria->compare('filename', $this->filename, true);
        $criteria->compare('thumbnail_filename', $this->thumbnail_filename, true);

        return new CActiveDataProvider(
            $this, array(
                'criteria'=>$criteria,
            )
        );
    }
}